import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/17 14:12
 * @description:
 */
public class Solution706 {
    public static class MyHashMap {
        public class Pair {
            int key;
            int value;

            public Pair(int key, int value) {
                this.key = key;
                this.value = value;
            }

            public int getKey() {
                return this.key;
            }

            public int getValue() {
                return this.value;
            }

            public void setValue(int value) {
                this.value = value;
            }
        }

        public LinkedList[] data;
        public static final int base = 769;

        public MyHashMap() {
            data = new LinkedList[base];
            for (int i = 0; i < base; i++) {
                data[i] = new LinkedList<Pair>();
            }
        }

        public void put(int key, int value) {
            int index = hash(key);
            Iterator<Pair> iter = data[index].iterator();

            while (iter.hasNext()) {
                Pair pair = iter.next();
                if (pair.key == key) {
                    pair.value = value;
                    return;
                }
            }

            data[index].addLast(new Pair(key, value));

        }

        public int get(int key) {
            int index = hash(key);
            Iterator<Pair> iter = data[index].iterator();
            while (iter.hasNext()) {
                Pair pair = iter.next();
                if (pair.key == key) {
                    return pair.value;
                }
            }
            return -1;
        }

        public void remove(int key) {
            int index = hash(key);
            Iterator<Pair> iter = data[index].iterator();
            while (iter.hasNext()) {
                Pair pair = iter.next();
                if (pair.key == key) {
                    data[index].remove(pair);
                }
            }
        }

        public int hash(int key) {
            return key % base;
        }
    }

}
